package com.chs.dao;

import com.chs.domain.ClickNum;
import com.chs.utils.JavaRedisClient;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 */
@Component
public class ClickNumDAO {


    /**
     * 根据天查询
     */
    public List<ClickNum> query(String key) throws Exception {

        List<ClickNum> list = new ArrayList<>();


        Map<String, String> map = JavaRedisClient.getAll(key);

        for(Map.Entry<String, String> entry: map.entrySet()) {
            ClickNum model = new ClickNum();
            model.setPid(entry.getKey());
            model.setClickValue(Long.parseLong(entry.getValue()));

            list.add(model);
        }

        return list;
    }

    public static void main(String[] args) throws Exception{
        ClickNumDAO dao = new ClickNumDAO();
        List<ClickNum> list = dao.query("pid::click");
        for(ClickNum model : list) {
            System.out.println(model.getPid() + " : " + model.getClickValue());
        }
    }

}
